/**
  ******************************************************************************
  * @file    p32f031_it.c
  * @author  MCU SYSTEM Team
  * @Version V1.0.0
  * @Date    2020-10-19
  * @brief   Interrupt Service Routines.
  ******************************************************************************

  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/

// #include "main.h"
#include "INT.h"
// #include "SPI_Flow.h"
#include "BSP.h"
// #include "uart.h"
#include "mg_api.h"
// extern SPI_HandleTypeDef SpiHandle;
/* Private includes ----------------------------------------------------------*/

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Private user code ---------------------------------------------------------*/

/* External variables --------------------------------------------------------*/

/******************************************************************************/
/*           Cortex-M0+ Processor Interruption and Exception Handlers          */
/******************************************************************************/
/**
 * @brief This function handles Non maskable interrupt.
 */
void NMI_Handler(void)
{
  /* USER CODE BEGIN NonMaskableInt_IRQn 0 */

  /* USER CODE END NonMaskableInt_IRQn 0 */
}

/**
 * @brief This function handles Hard fault interrupt.
 */
void HardFault_Handler(void)
{
  /* USER CODE BEGIN HardFault_IRQn 0 */

  /* USER CODE END HardFault_IRQn 0 */
  while (1)
  {
    //		delay_ms(5000);
    //		printf("HardFault_Handler");
    /* USER CODE BEGIN W1_HardFault_IRQn 0 */
    /* USER CODE END W1_HardFault_IRQn 0 */
  }
}

/**
 * @brief This function handles System service call via SWI instruction.
 */
void SVC_Handler(void)
{
  /* USER CODE BEGIN SVCall_IRQn 0 */

  /* USER CODE END SVCall_IRQn 0 */
}

/**
 * @brief This function handles Pendable request for system service.
 */
void PendSV_Handler(void)
{
  /* USER CODE BEGIN PendSV_IRQn 0 */

  /* USER CODE END PendSV_IRQn 0 */
}
volatile unsigned int SysTick_Count = 0;
unsigned int GetSysTickCount(void) // porting api
{
  return SysTick_Count;
}
static volatile unsigned int SysCount;
unsigned int GetCurrentTick(void)
{
  return SysCount;
}
/**
 * @brief This function handles System tick timer.
 */
void SysTick_Handler(void)
{
  SysTick_Count++;
}

/******************************************************************************/
/* P32F031 Peripheral Interrupt Handlers                                    */
/* Add here the Interrupt Handlers for the used peripherals.                  */
/* For the available peripheral interrupt handler names,                      */
/* please refer to the startup file (startup_xm32f1xx.s).                    */
/******************************************************************************/

/**
 * @brief This function handles WWDG Interrupt .
 */
void WWDG_IRQHandler(void)
{
  /* USER CODE BEGIN WWDG_IRQn 0 */

  /* USER CODE END WWDG_IRQn 0 */
}
void PVD_IRQHandler(void)
{
}
void RTC_IRQHandler(void)
{
}
void FLASH_IRQHandler(void)
{
}
void RCC_IRQHandler(void)
{
}
void IRQ_HANDLER(void)
{
  SysCount = SysTick->VAL;
  __HAL_GPIO_EXTI_CLEAR_FLAG(IRQ_PIN);
  // HAL_GPIO_EXTI_IRQHandler(IRQ_PIN);
}

// extern uint8_t Over;
void DMA1_Channel1_IRQHandler(void)
{
  DMA1->IFCR |= 0x00000001;
}
void DMA1_Channel2_3_IRQHandler(void)
{
  DMA1->IFCR |= 0x00000010;
}

void ADC_COMP_IRQHandler(void)
{
}
void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
{
}
void TIM1_CC_IRQHandler(void)
{
}

void TIM3_IRQHandler(void)
{
}
/*void TIM6_LPTIM_IRQHandler(void)
{
}
*/
void TIM14_IRQHandler(void)
{
}

void TIM16_IRQHandler(void)
{
}
void TIM17_IRQHandler(void)
{
}
void I2C1_IRQHandler(void)
{
}
void SPI1_IRQHandler(void)
{
  u32 i = 0;
  // HAL_SPI_IRQHandler(&Spi1Handle);
  i = SPI1->DR;
  i = SPI1->SR;
}
void SPI2_IRQHandler(void)
{
}
void USART1_IRQHandler(void)
{
  UART_INT_Callback();
}
void USART2_IRQHandler(void)
{
}
void LPUART_IRQHandler(void)
{
}
